package client;
import java.io.Serializable;

import javax.swing.JOptionPane;

public class LogIn implements Serializable
{
	public String ip = null;
	public String UserName = null;
	public String Password = null;
	
	public static boolean mainFlag = false;
	public static ClientConsole conn;
	public static User usr;
	
	public LogIn(String u, String p, String i) 
	{
		ip = i;
		UserName = u;
		Password = p;
	}
	
	public void confirmUserData(User u, ClientConsole cc)	
	{
		conn = cc;
		if(UserName.equals("") || Password.equals(""))
		{
			JOptionPane.showMessageDialog(null,"One or more fields are empty, Please try again !","Login Eror",JOptionPane.ERROR_MESSAGE);
			mainFlag = false;
		}
		else
		{
			u.setipAdd(this.ip);
			u.setUserName(this.UserName);
			u.setPassword(this.Password);

			conn.accept(u);	
			
			while(conn.flag == false);
			conn.flag = false;
			
			usr = (User)conn.getResult();
			
			if(usr.getStatus().equals("IN") || usr.getStatus().equals("WRONG")/* || usr.getStatus().equals("FROZEN")*/)
			{	
				if(usr.getStatus().equals("IN"))
					JOptionPane.showMessageDialog(null,"This user is already logged in !","Login Eror",JOptionPane.ERROR_MESSAGE);	
				if(usr.getStatus().equals("WRONG"))	
					JOptionPane.showMessageDialog(null,"Username and/or Password incorrect, reenter details ","Login Eror",JOptionPane.ERROR_MESSAGE);	
				//if(usr.getStatus().equals("FROZEN"))	
					//JOptionPane.showMessageDialog(null,"This user has been frozen, please contact Aflalo for more details ","Login Eror",JOptionPane.ERROR_MESSAGE);	
				mainFlag = false;
			}
			else mainFlag = true;
		}
	}
}
